﻿Ext.QuickTips.init();
Ext.Ajax.timeout = 90000000;
Ext.form.Field.prototype.msgTarget = 'side';
// var thecss = getCookie("css");
// thecss = thecss == '' ? 'blue' : thecss;
// Ext.util.CSS.swapStyleSheet("theme", getSitePath() + "/js/ext-2.0/resources/css/xtheme-" + thecss + ".css");

// alert (document.getElementById("theme").href);
//function alert(msg) {
//	Ext.Msg.show({
//				title : '亚信联创业务网关(SGW)系统',
//				msg : msg,
//				minWidth : 200,
//				buttons : Ext.Msg.OK,
//				model : false,
//				icon : Ext.MessageBox.INFO
//			});
//}

function alertError() {
	Ext.Msg.show({
				title : '亚信联创业务网关(SGW)系统',
				msg : msg,
				buttons : Ext.Msg.OK,
				icon : Ext.MessageBox.ERROR
			});
};

function alertSucc() {
	Ext.Msg.show({
				title : '亚信联创业务网关(SGW)系统',
				msg : msg,
				buttons : Ext.Msg.OK,
				icon : Ext.MessageBox.OK
			});
};

// Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
// // path : "/exchange",
// expires : new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 30))
// // 30 days
// // domain : getSitePath()
// }));
// Ext.util.CSS
// .swapStyleSheet("theme", getSitePath()
// + "/ext-2.0/resources/css/xtheme-"
// + Ext.state.Manager.getProvider().get('theme', 'blue')
// + ".css");

// validator for EditorGridPanel
function validateEditorGridPanel(gridId) {
	var grid = Ext.getCmp(gridId);
	var rows = grid.store.data.length;
	var cols = grid.colModel.config.length;
	
	for (var row = 0; row < rows; row++) {
		var record = grid.store.getAt(row);
		for (var col = 0; col < cols; col++) {
			var cellEditor = grid.colModel.getCellEditor(col, row);
			if (cellEditor != undefined) {
				var columnName = grid.colModel.getDataIndex(col);
				var columnValue = record.data[columnName];
				cellEditor.field.setValue(columnValue);
				if (!cellEditor.field.isValid()) {
					 grid.startEditing(row, col);
					 alert('请按照提示填写!');
					 return false;
				}
			}
		}
	}
	return true;
};

function validateEditorGridPanel_Vari(gridId) {
	var grid = Ext.getCmp(gridId);
	var rows = grid.store.data.length;
	var cols = grid.colModel.config.length;
	
	for (var row = 0; row < rows; row++) {
		var record = grid.store.getAt(row);
		var getValueMeth = record.get('getValueMode');
		for (var col = 0; col < cols; col++) {
			
			var cellEditor = grid.colModel.getCellEditor(col, row);
			if (cellEditor != undefined) {
				var columnName = grid.colModel.getDataIndex(col);
				var columnValue = record.data[columnName];
				cellEditor.field.setValue(columnValue);
				if (!cellEditor.field.isValid()) {
					if(((getValueMeth==1)&&(columnName!='sourceAvp')&&(columnName!='sourceAvpType'))||((getValueMeth==2)&&(columnName!='sourceData'))||(getValueMeth==3)||(getValueMeth==0)){
						datastore.rowId_va = row;
						grid.startEditing(row, col);
						alert('请按照提示填写!');
						return false;
					}
					
				}
			}
			
		}
	}
	return true;
};

function validateEditorGridPanel_func(gridId) {
	var grid = Ext.getCmp(gridId);
	var rows = grid.store.data.length;
	var cols = grid.colModel.config.length;
//	var basemethodStore = combobox.basemethodStore();
//	basemethodStore.load();
	for (var row = 0; row < rows; row++) {
		var record = grid.store.getAt(row);
		var callfunId = record.get('callFuncId');
		var index = datastore.basemethodStore.find('baseMethodId', callfunId);
		var paramCount=-1;
		if(index != -1){
			paramCount = datastore.basemethodStore.getAt(index).get('baseMethodParamcount');
		}
		for (var col = 0; col < cols; col++) {
			
			var cellEditor = grid.colModel.getCellEditor(col, row);
			if (cellEditor != undefined) {
				var columnName = grid.colModel.getDataIndex(col);
				var columnValue = record.data[columnName];
				cellEditor.field.setValue(columnValue);
				if (!cellEditor.field.isValid()) {
					if(((paramCount==1)&&(columnName!='funcParam2Type')&&(columnName!='funcParam2')&&(columnName!='funcParam3')&&(columnName!='funcParam3Type'))||((paramCount==2)&&(columnName!='funcParam3Type')&&(columnName!='funcParam3'))||(paramCount==3)||(paramCount==-1)){
						datastore.rowId_fc = row;
						grid.startEditing(row, col);
						alert('请按照提示填写!');
						return false;
					}
					
				}
			}
			
		}
	}
	return true;
};

// rowContextMenu for copy start
var clipboard = undefined;
var rowContextMenuEvent = function(grid, rowIndex, event) {
	event.preventDefault();
	var sm = grid.getSelectionModel();
	if (sm.isSelected(rowIndex)) {
		sm.selectRow(rowIndex, true);
	} else {
		sm.selectRow(rowIndex, false);
	}
	var records = sm.getSelections();
	var array = new Array();
	for (var i = 0; i < records.length; i++) {
		var record = records[i];
		array.push(record.data);
	}
	
	getRowContextMenu(array).showAt(event.getXY());// 取得鼠标点击坐标，展示菜单
};

function getRowContextMenu(array) {
	return new Ext.menu.Menu({
				items : [{
							// id : 'rowContextMenu_copy',
							text : '复制',
							iconCls : 'copy',
							tip : '复制该条记录',
							handler : function() {
								clipboard = array;
							}
						}]
			});
};


var clipboard_ddcEnume = undefined;
var clipboard_ddcGroup = undefined;
var clipboard_ddcCommand = undefined;
var clipboard_ddcCommandRule = undefined;


var rowContextMenuEvent_ddc = function(grid, rowIndex, event) {
	
	event.preventDefault();
	var sm = grid.getSelectionModel();
	if (sm.isSelected(rowIndex)) {
		sm.selectRow(rowIndex, true);
	} else {
		sm.selectRow(rowIndex, false);
	}
	var records = sm.getSelections();
	var array = new Array();
	for (var i = 0; i < records.length; i++) {
		var record = records[i];
		array.push(record.data);
	}
	if(grid.id == 'grid_dcAvpInfoEnume'){
		getRowContextMenu_ddc(array,'Enume').showAt(event.getXY());// 取得鼠标点击坐标，展示菜单
	}else if(grid.id == 'grid_dcAvpInfoGroup'){
		getRowContextMenu_ddc(array,'Group').showAt(event.getXY());// 取得鼠标点击坐标，展示菜单
	}else if(grid.id == 'grid_dicAppCommand'){
		getRowContextMenu_ddc(array,'Command').showAt(event.getXY());// 取得鼠标点击坐标，展示菜单
	}else if(grid.id == 'grid_dicAppCommandRule'){
		getRowContextMenu_ddc(array,'CommandRule').showAt(event.getXY());// 取得鼠标点击坐标，展示菜单
	}
};
function getRowContextMenu_ddc(array,avpType) {
	return new Ext.menu.Menu({
				items : [{
							// id : 'rowContextMenu_copy',
							text : '复制',
							iconCls : 'copy',
							tip : '复制该条记录',
							handler : function() {
								if(avpType == 'Enume'){
									clipboard_ddcEnume = array;
								}else if(avpType == 'Group'){
									clipboard_ddcGroup = array;
								}else if(avpType == 'Command'){
									clipboard_ddcCommand = array;
								}else if(avpType == 'CommandRule'){
									clipboard_ddcCommandRule = array;
								}
							}
						}]
			});
};



// rowContextMenu for copy end
// validator for the same record by db unique field
function validateSameRecord(gridId, colArr) {
	var grid = Ext.getCmp(gridId);
	var rows = grid.store.data.length;
	if (rows == 1) {
		return true;
	}
	if (colArr.length != 0) {
		var columnName = new Array();
		var columnHeader = new Array();
		for (var index = 0; index < colArr.length; index++) {
			columnName[index] = grid.colModel.getDataIndex(colArr[index]);
			columnHeader[index] = grid.colModel.getColumnHeader(colArr[index]);
		}
		var records = grid.store.getRange();
		var ary = new Array();
		for (var i = 0; i < records.length; i++) {
			var record = records[i];
			for (var m = 0; m < columnName.length; m++) {
				if (m == 0) {
					ary[i] = record.get(columnName[m]);
				} else {
					ary[i] += ',' + record.get(columnName[m]);
				}
			}
			ary[i] += '###' + (i + 1);
		}
		var sortArr = ary.sort();
		var msg;
		for (var i = 0; i < sortArr.length - 1; i++) {
			var o1 = sortArr[i].split('###');
			var o2 = sortArr[i + 1].split('###');
			if (o1[0] == o2[0]) {
				for (var k = 0; k < columnHeader.length; k++) {
					if (k == 0) {
						msg = '列"' + columnHeader[k];
					} else {
						msg += ',' + columnHeader[k];
					}
				}
				msg += '"\n';
				msg += '值' + '"' + o1[0] + '"' + '\n';
				msg += '第' + o1[1] + '行与第' + o2[1] + '行数据重复！';
				alert(msg);
				return false;
			}
		}
	}
	return true;
};

function validateChaRecord(gridId, colArr) {
	var grid = Ext.getCmp(gridId);
	var rows = grid.store.data.length;
	if (rows == 1) {
		return true;
	}
	if (colArr.length != 0) {
		var records = grid.store.getRange();
		var ary = new Array();
		for (var i = 0; i < records.length; i++) {
			var record = records[i];
			record.get(colArr[0]);
//			alert(record[grid.colModel.getColumnHeader(4)]);
			if(record.get(colArr[0])>record.get(colArr[1])){
//				alert("最小通道数要小于最大通道数");
				return false;
			}else{
//				alert(1)
				continue;
			}
		}
		return true;
	}
};

/** ************************************************************
 * simpleGrid 封装了项目通用的Ext.grid.EditorGridPanel
 * 
 * @author huangxun
 * @version 2011-08-10
 */
var simpleGrid = function() {
	
};

simpleGrid.prototype.gridId = new String();
simpleGrid.prototype.gridTitle = new String();
simpleGrid.prototype.gridColumnModel = new Object();
simpleGrid.prototype.gridBorder = true;
simpleGrid.prototype.gridForceFit = true;
simpleGrid.prototype.gridSimpleBbar = false;
simpleGrid.prototype.storeAction = new String();
simpleGrid.prototype.storeParams = new Object();
simpleGrid.prototype.storeFields = new Object();
simpleGrid.prototype.validateAction = new String();
simpleGrid.prototype.validateParams = new Object();
simpleGrid.prototype.submitAction = new String();
simpleGrid.prototype.submitParams = new Object();
simpleGrid.prototype.modeDisable = true;
simpleGrid.prototype.moreActions = new Array();

/** ************************************************************
 * 锁定时，指定前台需要验证的值不重复列
 */
simpleGrid.prototype.onMode$uniquecolumns = new Array();

/** ************************************************************
 * 锁定时，验证表单数据是否规范
 */
simpleGrid.prototype.onMode$datavalidate = function(record) {
	alert('Please override onMode$datavalidate !');
	return false;
};

/** ************************************************************
 * 锁定时，判断modified的数据属于新增还是修改
 */
simpleGrid.prototype.onMode$addormodify = function(record) {
	alert('Please override onMode$addormodify !');
	return null;
};

/** ************************************************************
 * 新增时，在列表中添加新的一行
 */
simpleGrid.prototype.onAdd$createnewrow = function() {
	alert('Please override onAdd$createnewrow !');
	return null;
};

/** ************************************************************
 * 删除时，默认无判断直接删除，如需业务判断，请重写该方法
 */
simpleGrid.prototype.onRemove$execute = function(record, array_remove, store) {
	array_remove.push(record.data);
	store.remove(record);
	return true;
};

/** ************************************************************
 * 默认为空的表格右键菜单，如果需要右键菜单请重写该方法
 */
simpleGrid.prototype.grid$rowcontextmenu = function(grid, rowIndex, event) {
	// alert('Please override grid$rowcontextmenu !');
	return null;
};

simpleGrid.prototype.stopEvent = function() {
	return false;
};

simpleGrid.prototype.rejectEdit = function(e) {
	return true;
};

/** ************************************************************
 * 创建Ext.grid.EditorGridPanel
 */
simpleGrid.prototype.createGrid = function() {
	
	/** ************************************************************
	 * 创建局部变量，避免simpleGrid属性方法无法调用到
	 */
	var gridId = this.gridId;
	var onMode$uniquecolumns = this.onMode$uniquecolumns;
	var onMode$datavalidate = this.onMode$datavalidate;
	var onMode$addormodify = this.onMode$addormodify;	
	var onAdd$createnewrow = this.onAdd$createnewrow;
	var onRemove$execute = this.onRemove$execute;
	
	/** ************************************************************
	 * 创建新增、修改、删除用到的数组
	 */
	var array_add = new Array();
	var array_modify = new Array();
	var array_remove = new Array();
	
	var stopEvent = this.stopEvent;
	var rejectEdit = this.rejectEdit;
	
	/** ************************************************************
	 * 解锁、锁定
	 */
	var validateAction = this.validateAction;
	var validateParams = this.validateParams;
	var onMode = function(btn) {
		if (btn.text == '解锁') {
			btn.setText('锁定');
			array_add.length = 0;
			array_modify.length = 0;
			grid.un('beforeedit', stopEvent);
			grid.on('beforeedit', rejectEdit);
			grid.addListener('rowcontextmenu', rowContextMenuEvent);
			Ext.getCmp(gridId + 'btnAdd').setDisabled(false);
			Ext.getCmp(gridId + 'btnRemove').setDisabled(false);
			Ext.getCmp(gridId + 'btnSubmit').setDisabled(true);
			Ext.getCmp(gridId + 'btnCancel').setDisabled(true);
		} else if (btn.text == '锁定') {
			for (var i = 0; i < onMode$uniquecolumns.length; i++) { // 验证表单数据值不重复
				if (onMode$uniquecolumns[i].length > 0 && !validateSameRecord(grid.getId(), onMode$uniquecolumns[i]))
					return;
			}
			if (!validateEditorGridPanel(grid.getId()))
				return;
			var array = store.getModifiedRecords();
			if (array != undefined && array != null && array != '') { // 有对数据进行新增、修改操作
				for (var i = 0; i < array.length; i++) { // 验证表单数据是否规范
					var record = array[i];
					if (!onMode$datavalidate(record))
						return;
				}
				for (var i = 0; i < array.length; i++) { // 判断被操作的数据是新增还是修改
					var record = array[i];
					if (typeof(onMode$addormodify) != 'undefined' && onMode$addormodify(record)) {
						array_add.push(record.data);
					} else {
						array_modify.push(record.data);
					}
				}
				if (validateAction.length > 0) { // 需要对修改后的数据进行后台验证
					validateParams.array_add = Ext.encode(array_add);
					validateParams.array_modify = Ext.encode(array_modify);
					validateParams.array_remove = Ext.encode(array_remove);
					Ext.Ajax.request({
						url : validateAction,
						params : validateParams,
						method : 'POST',
						sync : true,
						success : function(response, options) {
							var result = Ext.util.JSON.decode(response.responseText);
							if (result.success) {
								btn.setText('解锁');
								grid.un('beforeedit', rejectEdit);
								grid.on('beforeedit', stopEvent);
								grid.removeListener('rowcontextmenu', rowContextMenuEvent);
								Ext.getCmp(gridId + 'btnAdd').setDisabled(true);
								Ext.getCmp(gridId + 'btnRemove').setDisabled(true);
								Ext.getCmp(gridId + 'btnSubmit').setDisabled(false);
								Ext.getCmp(gridId + 'btnCancel').setDisabled(false);
								clipboard = undefined;
							} else {
								array_add = new Array();
								array_modify = new Array();
								alert(result.msg);
								return;
							}
						},
						failure : function(response, options) {
							alert('与后台验证交互失败！');
							return;
						}
					});
				} else { // 不需要对修改后的数据进行后台验证
					btn.setText('解锁');
					grid.un('beforeedit', rejectEdit);
					grid.on('beforeedit', stopEvent);
					grid.removeListener('rowcontextmenu', rowContextMenuEvent);
					Ext.getCmp(gridId + 'btnAdd').setDisabled(true);
					Ext.getCmp(gridId + 'btnRemove').setDisabled(true);
					Ext.getCmp(gridId + 'btnSubmit').setDisabled(false);
					Ext.getCmp(gridId + 'btnCancel').setDisabled(false);
					clipboard = undefined;
				}
			} else { // 没对数据进行新增、修改操作
				btn.setText('解锁');
				grid.un('beforeedit', rejectEdit);
				grid.on('beforeedit', stopEvent);
				grid.removeListener('rowcontextmenu', rowContextMenuEvent);
				Ext.getCmp(gridId + 'btnAdd').setDisabled(true);
				Ext.getCmp(gridId + 'btnRemove').setDisabled(true);
				Ext.getCmp(gridId + 'btnSubmit').setDisabled(array_remove.length == 0);
				Ext.getCmp(gridId + 'btnCancel').setDisabled(array_remove.length == 0);
				clipboard = undefined;
			}
		}
	};
	
	/** ************************************************************
	 * 增加
	 */
	var onAdd = function(btn) {
		var count = store.getCount();
		var p = onAdd$createnewrow();
		if (typeof p != 'undefined' && p != null)
			store.insert(count, p);
	};

	/** ************************************************************
	 * 删除
	 */
	var onRemove = function(btn) {	
		var records = grid.getSelectionModel().getSelections();
		for (var i = 0; i < records.length; i++) {
			var record = records[i];
			onRemove$execute(record, array_remove, store);
		}
	};

	/** ************************************************************
	 * 提交
	 */
	var submitAction = this.submitAction;
	var submitParams = this.submitParams;
	var onSubmit = function(btn) {
		btn.setDisabled(true);
		submitParams.array_add = Ext.encode(array_add);
		submitParams.array_modify = Ext.encode(array_modify);
		submitParams.array_remove = Ext.encode(array_remove);
		Ext.Ajax.request({
			url : submitAction,
			method : 'post',
			success : function(response, option) {
				Ext.decode(response.responseText);
				array_add = new Array();
				array_remove = new Array();
				array_modify = new Array();
				Ext.getCmp(gridId + 'btnAdd').setDisabled(true);
				Ext.getCmp(gridId + 'btnRemove').setDisabled(true);
				Ext.getCmp(gridId + 'btnSubmit').setDisabled(true);
				Ext.getCmp(gridId + 'btnCancel').setDisabled(true);
				store.reload();
			},
			failure : function(response, option) {
				btn.setDisabled(false);
			},
			params : submitParams
		});
	};

	/** ************************************************************
	 * 取消
	 */
	var onCancel = function(btn) {
		array_add = new Array();
		array_remove = new Array();
		array_modify = new Array();
		Ext.getCmp(gridId + 'btnSubmit').setDisabled(true);
		Ext.getCmp(gridId + 'btnCancel').setDisabled(true);
		store.reload();
	};
	
	/** ************************************************************
	 * 定义数据集
	 */
	var store = new Ext.data.Store({
		pruneModifiedRecords : true,
		proxy : new Ext.data.HttpProxy({url : this.storeAction}),
		baseParams : this.storeParams,
		reader : new Ext.data.JsonReader({
			totalProperty : "total",
			root : "root",
			fields: this.storeFields
		})
	});
	
	/** ************************************************************
	 * 定义工具栏
	 */
	var modeDisable = this.modeDisable;
	var moreActions = this.moreActions;
	var tbar = function() {
		var result = [
			{text : '解锁', id : gridId + 'btnMode', iconCls : 'anchor', handler : onMode, disabled : modeDisable}, 
			{text : '增加', id : gridId + 'btnAdd', iconCls : 'add', disabled : true, handler : onAdd}, 
			{text : '删除', id : gridId + 'btnRemove', iconCls : 'delete', disabled : true, handler : onRemove}, 
			'-', 
			{text : '提交', id : gridId + 'btnSubmit', iconCls : 'accept', disabled : true, handler : onSubmit}, 
			{text : '取消', id : gridId + 'btnCancel', iconCls : 'cancel', disabled : true, handler : onCancel}
		];
		if (typeof(moreActions) == 'object' && moreActions.length > 0) {
			for (var i = 0; i < moreActions.length; i++) {
		    	result.push(moreActions[i]);
			}
		}
		return result;
	};
	
	/** ************************************************************
	 * 定义状态栏
	 */
	var bbar = new Ext.PagingToolbar({
		pageSize : 20,
		store : store,
		displayInfo : true,
		displayMsg : '显示第 {0} 条到第 {1} 条记录，一共 {2} 条',
		emptyMsg : "没有记录"
	});
	var simplebbar = new Ext.PagingToolbar({
		pageSize : 10,
		store : store,
		displayInfo : true,
		displayMsg : '共 {2} 条',
		emptyMsg : "没有记录"
	});
	if (this.gridSimpleBbar) bbar = simplebbar;
	
	/** ************************************************************
	 * 创建Ext.grid.EditorGridPanel，并返回
	 */
	var grid = new Ext.grid.EditorGridPanel({
		id : this.gridId,
		title : this.gridTitle,
//		renderTo : 'grid',
		colModel : this.gridColumnModel,
		iconCls : 'icon-grid',
		store : store,
		border : this.gridBorder,
		stripeRows : true,
		clicksToEdit : 1,
		selModel : new Ext.grid.RowSelectionModel({
			singleSelect : false,
			moveEditorOnEnter : true
		}),
		viewConfig : {
			forceFit : this.gridForceFit//,
//			autoFill : !this.gridForceFit, // 水平滚动条
//			autoScroll : !this.gridForceFit // 垂直滚动条
		},
		loadMask : {
		    msg : '正在加载数据，请稍侯......'
		},
		listeners : {
		    'beforeedit' : stopEvent,
		    'rowcontextmenu' : this.grid$rowcontextmenu
		},
		tbar : tbar(),
		bbar : bbar
	});
	
	return grid;
};

/** ************************************************************
 * tips 封装了气泡方式的提示消息类
 * 
 * @author huangxun
 * @version 2011-09-02
 */
var tips = {
	temp : {},
	/** ************************************************************
	 * 弹出气泡
	 * 
	 * @param string
	 *            msg 提示文字内容
	 * @param string
	 *            id 要弹出提示的目标对象的id,如果id错误/null/false/0则主窗口弹出
	 * @param int
	 *            time 定时消失时间毫秒数,如果为null/0/false则不定时
	 * @param string
	 *            color 提示内容的背景颜色格式为#000000
	 * @param int
	 *            width 提示窗宽度,默认300
	 */
	show : function(msg, id, time, color, width) {
		var target = this._get(id);
		if (!target) {
			id = 'window';
		}

		// 如果弹出过则移除重新弹出
		if (this._get(id + '_tips')) {
			this.remove(id);
		}

		// 设置默认值
		msg = msg || 'error';
		color = color || '#ea0000';
		width = width || 300;
		time = time ? parseInt(time) : false;

		if (id == 'window') {
			var y = document.body.clientHeight / 2 + document.body.scrollTop;
			var x = (document.body.clientWidth - width) / 2;
			var textAlign = 'center', fontSize = '15', fontWeight = 'bold';
		} else {
			// 获取对象坐标信息
			var y = 0;
			var x = 0;
			while (target != null) {
				y += target.offsetTop - target.scrollTop;
				x += target.offsetLeft - target.scrollLeft;
				target = target.offsetParent;
			}
			var textAlign = 'left', fontSize = '12', fontWeight = 'normal';
		}

		// 弹出提示
		var tipsDiv = this._create({
			display : 'block',
			position : 'absolute',
			zIndex : '1000002',
			width : (width - 2) + 'px',
			left : (x + 31) + 'px',
			padding : '5px',
			color : '#ffffff',
			fontSize : fontSize + 'px',
			backgroundColor : color,
			textAlign : textAlign,
			fontWeight : fontWeight,
			filter : 'Alpha(Opacity=50)',
			opacity : '0.7'
		}, {
			id : id + '_text',
			innerHTML : msg,
			onclick : function() {
				tips.hidden(id);
			}
		});
		document.body.appendChild(tipsDiv);
		tipsDiv.style.top = (y - tipsDiv.offsetHeight - 12) + 'px';
		document.body.appendChild(this._create({
			display : 'block',
			position : 'absolute',
			zIndex : '1000001',
			width : (width - 2) + 'px',
			height : (tipsDiv.offsetHeight - 2) + 'px',
			left : (x + 30) + 'px',
			top : (y - tipsDiv.offsetHeight - 11) + 'px',
			backgroundColor : color,
			filter : 'Alpha(Opacity=50)',
			opacity : '0.7'
		}, {
			id : id + '_bg'
		}));
		if (id != 'window') {
			var arrow = this._create({
				display : 'block',
				position : 'absolute',
				overflow : 'hidden',
				zIndex : '1000000',
				width : '20px',
				height : '10px',
				left : (x + 50) + 'px',
				top : (y - 13) + 'px'
			}, {
				id : id + '_arrow'
			});
			arrow.appendChild(this._create({
				display : 'block',
				width : '0px',
				height : '10px',
				borderTop : '10px solid ' + color,
				borderRight : '10px solid #fff',
				borderLeft : '10px solid #fff',
				filter : 'Alpha(Opacity=70)',
				opacity : '0.8'
			}));
			document.body.appendChild(arrow);
		}

		// 标记已经弹出
		this.temp[id] = id;

		// 如果定时关闭
		if (time) {
			setTimeout(function() {
				tips.hidden(id);
			}, time);
		}

		return id;
	},
	/** ************************************************************
	 * 隐藏提示
	 * 
	 * @param string
	 *            id 要隐藏提示的id,如果要隐藏主窗口提示id为window,如果要隐藏所有提示id为空即可
	 */
	hidden : function(id) {
		if (!id) {
			for ( var i in this.temp) {
				this.hidden(i);
			}
			return;
		}
		var t = this._get(id + '_text'), d = this._get(id + '_bg'), a = this
				._get(id + '_arrow');
		if (t) {
			t.parentNode.removeChild(t);
		}
		if (d) {
			d.parentNode.removeChild(d);
		}
		if (a) {
			a.parentNode.removeChild(a);
		}
	},
	_create : function(set, attr) {
		var obj = document.createElement('div');
		for ( var i in set) {
			obj.style[i] = set[i];
		}
		for ( var i in attr) {
			obj[i] = attr[i];
		}
		return obj;
	},
	_get : function(id) {
		return document.getElementById(id);
	}
};